<?php

declare(strict_types=1);
namespace App\Http\Controllers\Api\Test;

use App\Http\Dto\Api\Test\TestBodyDto;
use App\Http\Dto\Api\Test\TestFormDto;
use App\Http\Dto\Api\Test\TestQueryDto;
use App\Http\Vo\DataSubmitVo;
use App\Http\Vo\Test\TestQueryVo;
use App\Logic\Api\User\UserLogic;
use Hesb\LaravelPlus\Annotation\Api;
use Hesb\LaravelPlus\Annotation\ApiOperation;
use Hesb\LaravelPlus\Annotation\ApiResponse;
use Hesb\LaravelPlus\Annotation\Contracts\RequestBody;
use Hesb\LaravelPlus\Annotation\Contracts\RequestFormData;
use Hesb\LaravelPlus\Annotation\Contracts\RequestQuery;
use Hesb\LaravelPlus\Annotation\Contracts\Valid;
use Hesb\LaravelPlus\Annotation\Controller;
use Hesb\LaravelPlus\Annotation\GetMapping;
use Hesb\LaravelPlus\Annotation\Inject;
use Hesb\LaravelPlus\Annotation\PostMapping;
use Hesb\LaravelPlus\Traits\Injectable;


#[Api(tags: '测试')]
#[Controller(prefix:"/api/api/test/test")]
class TestController
{
    #[ApiOperation('测试query')]
    #[GetMapping(path: 'query')]
    #[ApiResponse(TestQueryVo::class)]
    public function query(#[RequestQuery] #[Valid] TestQueryDto $dto){
        //逻辑层高处理对
        $params = get_object_vars($dto);
        $params['time'] = time();
        $params['token'] = csrf_token();
        //逻辑层返回数组
        //根据响应对象，约束响应数据
        return json_encode($params);
    }

    #[ApiOperation('测试body')]
    #[PostMapping(path: 'body')]
    #[ApiResponse(DataSubmitVo::class)]
    public function body(#[RequestBody] #[Valid] TestBodyDto $dto){
        //逻辑层返回数组
        $result = $this->logic->add($dto);
        //根据响应对象，约束响应数据
        return $result;
    }

    #[ApiOperation('测试form')]
    #[PostMapping(path: 'form')]
    #[ApiResponse(DataSubmitVo::class)]
    public function form(#[RequestFormData] #[Valid] TestFormDto $dto){
        var_dump($dto);
        $params = [];

        $params['time'] = time();
        //逻辑层返回数组
        //根据响应对象，约束响应数据
        return response()->json($params);
    }


}
